<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>课程学习</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css">
    <style>
        body {
            background: linear-gradient(120deg, #e0e7ff 0%, #f5f5f5 100%);
            min-height: 100vh;
        }
        h2 {
            text-align: center;
            color: #222;
            font-size: 2rem;
            margin-top: 40px;
            margin-bottom: 32px;
            letter-spacing: 1px;
        }
        .course-list {
            max-width: 700px;
            margin: 0 auto 40px auto;
        }
        .course-item {
            background: #fff;
            border-radius: 12px;
            box-shadow: 0 2px 12px #e0e7ff;
            padding: 28px 32px 20px 32px;
            margin-bottom: 28px;
            transition: box-shadow 0.18s, transform 0.18s;
            position: relative;
        }
        .course-item:hover {
            box-shadow: 0 8px 32px #b3d1ff;
            transform: translateY(-2px) scale(1.02);
        }
        .course-title {
            font-size: 1.35rem;
            color: #1677ff;
            font-weight: 600;
            text-decoration: none;
            display: flex;
            align-items: center;
        }
        .course-title i {
            margin-right: 10px;
            color: #1677ff;
            font-size: 1.2em;
        }
        .course-desc {
            color: #555;
            margin: 10px 0 8px 0;
            font-size: 1.08rem;
        }
        .course-meta {
            color: #888;
            font-size: 0.98rem;
            margin-bottom: 10px;
        }
        .btn-study {
            display: inline-block;
            margin-top: 8px;
            padding: 8px 28px;
            background: #1677ff;
            color: #fff;
            border-radius: 6px;
            font-size: 1.08rem;
            font-weight: 500;
            box-shadow: 0 1px 4px #e0e7ff;
            transition: all 0.18s;
            text-decoration: none;
            border: none;
            cursor: pointer;
        }
        .btn-study:hover {
            background: #1256b8;
            color: #fff;
            box-shadow: 0 4px 16px #b3d1ff;
            transform: translateY(-2px) scale(1.04);
        }
        .no-courses {
            text-align: center;
            color: #888;
            font-size: 1.1rem;
            margin-top: 40px;
        }
    </style>
</head>
<body>
    <a href="/index" style="display:inline-block;margin:24px 0 0 24px;padding:6px 16px;background:#e6f0ff;color:#1677ff;border-radius:6px;text-decoration:none;font-weight:500;box-shadow:0 1px 4px #e0e7ff;">返回首页</a>
    <h2>课程学习页面</h2>
    <div class="course-list">
        <div th:each="course : ${courses}" class="course-item">
            <span class="course-title"><i class="fa-solid fa-graduation-cap"></i><span th:text="${course.title}"></span></span>
            <div class="course-desc" th:text="${course.description}"></div>
            <div class="course-meta">
                讲师：<span th:text="${course.instructor != null ? (course.instructor.fullName != null ? course.instructor.fullName : course.instructor.username) : '未知'}"></span>
            </div>
            <a th:if="${!#lists.isEmpty(course.modules) and !#lists.isEmpty(course.modules[0].contents)}"
               href="#"
               th:attr="data-course-id=${course.id},data-content-id=${course.modules[0].contents[0].id},data-url=${course.modules[0].contents[0].contentUrl}"
               class="btn-study"
               onclick="recordAndGo(this);return false;">
                <i class="fa-solid fa-arrow-right-to-bracket"></i> 进入学习
            </a>
            <a th:if="${#lists.isEmpty(course.modules) or #lists.isEmpty(course.modules[0].contents)}"
               th:href="@{'/courses/' + ${course.id}}" class="btn-study">
                <i class="fa-solid fa-arrow-right-to-bracket"></i> 进入学习
            </a>
        </div>
        <div th:if="${#lists.isEmpty(courses)}" class="no-courses">暂无课程</div>
    </div>
    <script>
    function recordAndGo(el) {
        var courseId = el.getAttribute('data-course-id');
        var contentId = el.getAttribute('data-content-id');
        var url = el.getAttribute('data-url');
        fetch('/api/progress/update', {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify({
                courseId: courseId,
                contentId: contentId,
                progressPercentage: 100, // 可根据实际内容动态计算
                isCompleted: false
            })
        }).then(function() {
            window.open(url, '_blank');
        });
    }
    </script>
</body>
</html> 